package models;

import java.util.ArrayList;
import java.util.HashMap;

import com.std.getstuffdone.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapter extends ArrayAdapter<HashMap<String, String>> {
	private final Context context;
	private final ArrayList<HashMap<String, String>> data;
 
	public MyAdapter(Context context, ArrayList<HashMap<String, String>> data) {
		super(context, R.layout.schedule_list_item, data);
		this.context = context;
		this.data = data;
		Log.d("this.data.size()", this.data.size() + " --");
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Log.d("inside getView", "iside getView");
		LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View rowView = inflater.inflate(R.layout.schedule_list_item, parent, false);
		TextView title = (TextView) rowView.findViewById(R.id.title);
		Log.d("title", title.getText().toString());
		TextView taskId = (TextView) rowView.findViewById(R.id.taskId);
		TextView startTime = (TextView) rowView.findViewById(R.id.startTime);
		TextView duration = (TextView) rowView.findViewById(R.id.duration);
		TextView priority = (TextView) rowView.findViewById(R.id.priority);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.statusicon);
		title.setText(data.get(position).get("title"));
		taskId.setText(data.get(position).get("taskId"));
		startTime.setText(data.get(position).get("startTime"));
		duration.setText(data.get(position).get("duration"));
		priority.setText(data.get(position).get("priority"));
 
		// Change icon based on name
		String s = data.get(position).get("status");
 
		System.out.println(s);
 
		if (s.equalsIgnoreCase("true")) {
			imageView.setImageResource(R.drawable.check32green);
		} else if (s.equalsIgnoreCase("false")) {
			imageView.setImageResource(R.drawable.check32);
		}
		return rowView;
	}
}

